package cn.dt.dthouse.controller;

import cn.dt.dthouse.pojo.Houseinfo;
import cn.dt.dthouse.pojo.Housetype;
import cn.dt.dthouse.pojo.Viewhouse;
import cn.dt.dthouse.service.HouseInfoService;
import cn.dt.dthouse.service.HousetypeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Api(tags = "相关接口",description = "提供的Resut API")
public class HouseController {
    @Resource
    HouseInfoService infoservice;
    @Resource
    HousetypeService typeservice;

    @RequestMapping("/query/type")
    @ApiOperation("查询户型信息")
    public List<Housetype> getSelectType(){
        return typeservice.getSelecttype();
    }

    @RequestMapping("/query/info")
    @ApiOperation("查询信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页数",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",dataType = "int")
    })
    public PageInfo<Viewhouse> getSelectInfo(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize",required = false,defaultValue = "3") Integer pageSize){
        PageInfo<Viewhouse> pageInfo=infoservice.getSelectHousePageInfo(pageNum, pageSize);

        return pageInfo;
    }

    @ApiOperation("根据id查询信息")
    @GetMapping("/queryinfo/by/id")
    @ApiImplicitParam(name = "id",value =" 编号",dataType = "int")
    public Houseinfo getSelectinfoByid(Integer id) {
        return infoservice.getSelecthouse(id);
    }
    @ApiOperation("添加房屋信息")
    @PostMapping("/add/person")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "housedesc",value = "房屋描述",dataType = "String"),
            @ApiImplicitParam(name = "typeid",value = "户型变好",dataType = "int"),
            @ApiImplicitParam(name = "mouthiyrent",value = "租金",dataType = "int")
    })
    public int getAdd(String housedesc,Integer typeid,Integer mouthiyrent){
        Houseinfo houseinfo=new Houseinfo();
        houseinfo.setHousedesc(housedesc);
        houseinfo.setTypeid(typeid);
        houseinfo.setMouthiyrent(mouthiyrent);
        houseinfo.setPublishdate(new Date());
        return infoservice.insert(houseinfo);
    }
}
